package Programa4;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import javax.swing.*;

public class Tabla extends JFrame {

    JTable tabla;

    public Tabla() {
        setSize(800, Main.n * 22 + 100);
        setLocation(10, 10);
        tabla = new JTable(Main.datos, Main.terminales);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLayout(new BorderLayout());
        add(tabla.getTableHeader(), BorderLayout.PAGE_START);
        add(tabla, BorderLayout.CENTER);
        JButton boton = new JButton("Calcular");
        boton.setPreferredSize(new Dimension(100, 30));
        boton.setText("Calcular");
        boton.setLabel("Calcular");
        boton.add(new JLabel("Calcular"));
        boton.setAction(new but_ac());
        JPanel flowPanel = new JPanel(new FlowLayout());
        flowPanel.add(boton);
        add(flowPanel, BorderLayout.PAGE_END);
        setVisible(true);
    }

    class but_ac extends AbstractAction {

        private Component JFrame;

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                Main.imprime();
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(JFrame, "Ha ocurrido un error, revisa que tus datos esten correctos");
            }
        }
    }
}
